package com.alipay.account.dal.dao.mybatis;

import com.alipay.account.dal.dao.UserAccountDAO;
import com.alipay.account.dal.domain.UserAccountDO;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author guangshu.wgs
 * @version MybatisUserAccountDAO.java 2017/12/5 account-demo-parent
 */
public class MybatisUserAccountDAO extends SqlSessionDaoSupport implements UserAccountDAO {
    public UserAccountDO getUserAccountByUidForUpdate(String userId) {
        Map<String, String> params = new HashMap<>();
        params.put("userId", userId);
        return (UserAccountDO) getSqlSession().selectOne("getUserAccountByUidForUpdate", params);
    }

    public UserAccountDO getUserAccountByUid(String userId) {
        Map<String, String> params = new HashMap<>();
        params.put("userId", userId);
        return (UserAccountDO) getSqlSession().selectOne("getUserAccountByUid", params);
    }

    public List<UserAccountDO> getAllUserAccounts() {
        Map<String, String> params = new HashMap<>();
        return (List) getSqlSession().selectList("getAllUserAccounts", params);
    }

    public int updateUserAccount(UserAccountDO userAccountDO) {
        return getSqlSession().update("updateUserAccount", userAccountDO);
    }

    public int addUserAmount(String userId, Long addAmount) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("addAmount", addAmount);
        return getSqlSession().update("addUserAmount", params);
    }

    public int addUser(UserAccountDO userAccountDO) {
        return getSqlSession().insert("addUser", userAccountDO);
    }

}
